import { defineStore } from "pinia";
import { ref } from "vue";
export const useToken = defineStore(
  "token",
  () => {
    //定义状态数据(state)
    const token = ref(null);
    //修改 token 的方法(action)
    const updateToken = (val: any) => {
      token.value = val;
    };
    //移除 token 的方法(action)
    const removeToken = () => {
      token.value = null;
    };
    //以对象形式返回
    return { token, updateToken, removeToken };
  },
  {
    persist: {
      key: "token",
      storage: sessionStorage,
    },
  }
);
